package com.Lyf.user.controller;


import com.Lyf.common.vo.ResultVO;
import com.Lyf.user.dao.UserDaoMp;
import com.Lyf.user.elasticsearch.index.Book;
import com.Lyf.user.elasticsearch.repository.BookRepository;
import com.Lyf.user.entity.User;
import com.Lyf.user.service.UserService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/user")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    @Resource
    private UserDaoMp userDaoMp;

    @Resource
    private BookRepository bookRepository;


    @Resource
    RabbitTemplate rabbitTemplate;

    @PostMapping("/test")
    public ResultVO test(int id)
    {
        User user = userService.selectUserById(id);
        System.out.println(user);
        return ResultVO.success().put("user",user);
    }

    @PostMapping("/test1")
    public ResultVO test1()
    {
        List<User> users = userDaoMp.selectList(new QueryWrapper<>());
        return ResultVO.success().put("users",users);
    }

    //es测试
    @RequestMapping(value = "/save")
    public String search()
    {
        Iterable<Book> all = bookRepository.findAll();
        log.info("测试info");
        log.debug("debug输出---");
        all.forEach(System.out::println);
        return "1";
    }

}
